<template>
	<view class="mainSet">
		<u-navbar  title="企业派单设置"  :background="background" title-color="#FFF" back-icon-color="#fff"></u-navbar>
		<!-- @click="versionClick" -->
		<view class="mainSet-li">
			<view class="">
				<span style="font-weight: bold; font-size: 36rpx;">鑫强建材</span>
				（允许派单）
			</view>
			<view class="" style="padding-top: 14rpx;">
				<u-switch v-model="checked" @change="change"></u-switch>
			</view>
				
		</view>
		<view class="mainSet-li">
			<view class="">
				<span style="font-weight: bold; font-size: 36rpx;">鑫利祥建材</span>
				（允许派单）
			</view>
			<view class="" style="padding-top: 14rpx;">
				<u-switch v-model="checkeddyf" @change="changedyf"></u-switch>
			</view>
				
		</view>
		<!-- <view class="mainSet-li" @click="deleteShow=true">
			<view class="">
				删除账号（谨慎操作）
			</view>
			<text></text>
		</view>
		<view class="mainSet-li" @click="sqFun">
			<view class="">
				授权管理
			</view>
			<text class="iconfont iconarrow_right"></text>
		</view>
		<view class="mainSet-out" @click="outLoginShow=true">
			退出登录
		</view>
		<u-modal v-model="outLoginShow" content="请确认是否退出登录" :show-cancel-button="true" @confirm="outLoginConfirm"></u-modal>
		<u-modal v-model="deleteShow" content="请确认是否注销" :show-cancel-button="true" @confirm="deleteConfirm"></u-modal>
		<u-toast ref="uToast" /> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				background: {
					backgroundColor: '#00a1f1',
				},
				outLoginShow: false,
				deleteShow: false,
				userinfo: JSON.parse(uni.getStorageSync('userinfo')),
				platform: false,
				checked: false,
				checkeddyf:false,
				kg:'',
				dyf:'',
				appversion: '1.0.0',
				zhid:''
			}
		},
		onLoad(ops) {
		
			let obj = JSON.parse(decodeURIComponent(ops.item))
			this.zhid = obj.ORMTB417ID
				console.log(this.zhid)
				this.qylistFun()
		},
		onShow() {
			// var that = this
			// this.platform = uni.getStorageSync('platform')
			// if (this.platform == true) {
			// 	plus.runtime.getProperty(plus.runtime.appid, function(widgetInfo) {
			// 		that.appversion = widgetInfo.version
			// 	});
			// }
			this.queSqFun()

		},
		methods: {
			change(status) {
				console.log(status);
				
				if(status==true){
					this.kg =1
				}
				if(status==false){
					this.kg =0
				}
				
				uni.showLoading({
					title: '请求中',
					mask: true
				});
				uni.request({
					url: this.baseUrl + '/orm/ormtb410/updateAuth',
					method: 'POST',
					dataType: 'json',
					data: {
						ORMTB410ID: this.userinfo.ORMTB410ID,
						ORMTB410CB12: this.kg
					},
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {
							console.log(res)
							if(res.data.data.ORMTB410CB12==0){
								this.checked =false
							}
							else{
								this.checked =true
							}
						} else {
							this.$refs.uToast.show({
								title: res.data.message,
								type: 'default',
								icon: false
							})
						}
						uni.hideLoading();
					},
					fail: (res) => {
						this.$refs.uToast.show({
							title: res.errMsg,
							type: 'default',
							icon: false
						})
						uni.hideLoading();
					}
				});
				
			},
			changedyf(status){
				console.log(status);
				
				if(status==true){
					this.dyf =1
				}
				if(status==false){
					this.dyf =0
				}
				
				uni.showLoading({
					title: '请求中',
					mask: true
				});
				uni.request({
					url: this.baseUrl + '/orm/ormtb410/updateAuth',
					method: 'POST',
					dataType: 'json',
					data: {
						ORMTB410ID: this.userinfo.ORMTB410ID,
						ORMTB410CB19: this.dyf
					},
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {
							console.log(res)
							if(res.data.data.ORMTB410CB19==0){
								this.checkeddyf =false
							}
							else{
								this.checkeddyf =true
							}
						} else {
							uni.showToast({
								title: res.data.message,
								type: 'default',
								icon: false
							})
						}
						uni.hideLoading();
					},
					fail: (res) => {
						uni.showToast({
							title: res.errMsg,
							type: 'default',
							icon: false
						})
						uni.hideLoading();
					}
				});
			},
			sqFun() {
				uni.navigateTo({
					url: '/pages/shouquan/shouquanAdmin/index'
				})
			},
			qylistFun(){
				uni.showLoading({
					title: '请求中',
					mask: true
				});
				uni.request({
					url: this.baseUrl + '/orm/ormtb417/selectCJ',
					method: 'POST',
					dataType: 'json',
					data: {
						ORMTB417ID: this.zhid
					},
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {
							console.log(res)
							if(res.data.data.ORMTB410CB12==0){
								this.checked =false
							}
							if(res.data.data.ORMTB410CB12==1){
								this.checked =true
							}
							if(res.data.data.ORMTB410CB19==0){
								this.checkeddyf =false
							}
							if(res.data.data.ORMTB410CB19==1){
								this.checkeddyf =true
							}
							
							
						} else {
							uni.showToast({
								title: res.data.message,
								type: 'default',
								icon: false
							})
						}
						uni.hideLoading();
					},
					fail: (res) => {
						uni.showToast({
							title: res.errMsg,
							type: 'default',
							icon: false
						})
						uni.hideLoading();
					}
				});
			},
			queSqFun(){
				uni.showLoading({
					title: '请求中',
					mask: true
				});
				uni.request({
					url: this.baseUrl + '/orm/ormtb410/selectAuth',
					method: 'POST',
					dataType: 'json',
					data: {
						ORMTB410ID: this.userinfo.ORMTB410ID
					},
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {
							console.log(res)
							if(res.data.data.ORMTB410CB12==0){
								this.checked =false
							}
							if(res.data.data.ORMTB410CB12==1){
								this.checked =true
							}
							if(res.data.data.ORMTB410CB19==0){
								this.checkeddyf =false
							}
							if(res.data.data.ORMTB410CB19==1){
								this.checkeddyf =true
							}
							
							
						} else {
							uni.showToast({
								title: res.data.message,
								type: 'default',
								icon: false
							})
						}
						uni.hideLoading();
					},
					fail: (res) => {
						uni.showToast({
							title: res.errMsg,
							type: 'default',
							icon: false
						})
						uni.hideLoading();
					}
				});
			},
			outLoginConfirm() {
				uni.showLoading({
					title: '请求中',
					mask: true
				});
				uni.request({
					url: this.baseUrl + '/system/quit',
					method: 'POST',
					dataType: 'json',
					data: {
						PERTB005ID: this.userinfo.PERTB005ID
					},
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {
							uni.clearStorageSync()
							uni.reLaunch({
								url: '/pages/APPlogin/index'
							})
						} else {
							this.$refs.uToast.show({
								title: res.data.message,
								type: 'default',
								icon: false
							})
						}
						uni.hideLoading();
					},
					fail: (res) => {
						this.$refs.uToast.show({
							title: res.errMsg,
							type: 'default',
							icon: false
						})
						uni.hideLoading();
					}
				});
			},
			versionClick() {
				uni.navigateTo({
					url: '/pages/mainUpdate/index'
				})
			},
			deleteConfirm() {
				console.log(this.userinfo.PERTB005ID)
				uni.showLoading({
					title: '请求中',
					mask: true
				});
				uni.request({
					url: this.baseUrl + '/per/pertb005/logout',
					method: 'POST',
					dataType: 'json',
					data: {
						PERTB005ID: this.userinfo.PERTB005ID
					},
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {
							this.$refs.uToast.show({
								title: '注销成功',
								type: 'default',
								icon: false
							})
							// uni.removeStorageSync('userinfo')
							uni.clearStorageSync()
							uni.reLaunch({
								url: '/pages/APPlogin/index'
							})
						} else {
							uni.showToast({
								title: res.data.message,
								type: 'default',
								icon: false
							})
						}
						uni.hideLoading();
					},
					fail: (res) => {
						this.$refs.uToast.show({
							title: res.errMsg,
							type: 'default',
							icon: false
						})
						uni.hideLoading();
					}
				});
			}
		}
	}
</script>

<style scoped>
	.mainSet {
		min-height: 100vh;
		width: 100vw;
		background-color: #E3E3E3;
	}

	.mainSet-out {
		height: 90rpx;
		line-height: 90rpx;
		background-color: #FFF;
		font-size: 30rpx;
		color: #333;
		text-align: center;
		margin-top: 30rpx;
	}

	.mainSet-li {
		display: flex;
		justify-content: space-between;
		height: 90rpx;
		line-height: 90rpx;
		background-color: #FFF;
		font-size: 30rpx;
		color: #333;
		padding: 0 40rpx;
	}

	.mainSet-li+.mainSet-li {
		margin-top: 20rpx;
	}

	.mainSet-li text {
		color: #999;
	}
</style>
